﻿namespace UnityEditor
{
    using System;
    using System.IO;
    using UnityEditorInternal;
    using UnityEngine;

    internal class SaveWindowLayout : EditorWindow
    {
        internal bool didFocus;
        internal string m_PreferencesName = EditorPrefs.GetString("LastLoadedLayoutName", string.Empty);

        private void OnGUI()
        {
            Event current = Event.current;
            bool flag = (current.type == EventType.KeyDown) && ((current.keyCode == KeyCode.Return) || (current.keyCode == KeyCode.KeypadEnter));
            GUI.SetNextControlName("m_PreferencesName");
            this.m_PreferencesName = EditorGUILayout.TextField(this.m_PreferencesName, new GUILayoutOption[0]);
            if (!this.didFocus)
            {
                this.didFocus = true;
                GUI.FocusControl("m_PreferencesName");
            }
            GUI.enabled = this.m_PreferencesName.Length != 0;
            if (GUILayout.Button("Save", new GUILayoutOption[0]) || flag)
            {
                base.Close();
                string path = Path.Combine(WindowLayout.GetLayoutsPath(), this.m_PreferencesName + ".wlt");
                Toolbar.lastLoadedLayoutName = this.m_PreferencesName;
                WindowLayout.SaveWindowLayout(path);
                InternalEditorUtility.ReloadWindowLayoutMenu();
                GUIUtility.ExitGUI();
            }
        }
    }
}

